#!/usr/bin/python
import os
from dcinstall import setup_py, debian, AbstractPackageInfo
from dcinstall.version import get_revisions, get_changelog_core, save_last_revision

class build(AbstractPackageInfo.build):
    sources_dir = os.path.realpath(os.path.dirname(__file__))
    build_dir = sources_dir
    result_dir = sources_dir + '/dist'

last_revision, cur_revision = get_revisions(build)

class info(AbstractPackageInfo):
    build = build
    version = '1.0-SVN%d' % cur_revision
    changelog_core = get_changelog_core(last_revision, cur_revision)
    name = 'dcinstall'
    maintainer = 'Maxim Oransky'
    maintainer_email = 'maxim.oransky@gmail.com'
    description = 'Installer'
    url = 'http://code.google.com/p/the-wheel-django-apps/'
    deb_depends = [
        'subversion (>= 1.4)',
        'python (>= 2.4)',
        'dpkg (>= 1.13)',
        'tar',
    ]
    license = 'GNU Lesser General Public License'
    classifiers = [
        'Environment :: Web Environment',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
    ]


###################
# 1. Classic setup.py installer
setup_py.create(info, skipfiles='.*\.pyc|.*\.pyo|\.svn')
os.system('python setup.py sdist --formats=zip,gztar')
setup_py.clean()

###################
# 2. Debian package

src_files = ['dist/%s-%s.tar.gz' % (info.name, info.version)]

debian.build_package(
    info,
    src_files,
    custom_deb_templates = {
        'postinst': '%PRESETS%/simple_python_package_postinst.template',
    },
)

os.system('mv %s*deb %s' % (info.name, info.build.result_dir))

# on sucess save mark current revision as "last builded"
save_last_revision(build, cur_revision)
